#include"HashTable.h"
int hashFunction1(char element[])
{
    return 1;
}
int hashFunction2(char element[])
{
    return (int)element[0];
}
int hashFunction4(char element[])
{
    int sum = 0, i = 0;
    while(element[i])
    {
        sum += element[i];
        i++;
    }
    return sum;
}
int hashFunction3(char element[])
{
    return strlen(element);
}
int hashFunction5(char element[])
{
    int len = strlen(element);
    int prevH = element[0];

    for(int i = 2; i < len; i++)
    {
        prevH = (prevH << 1)^element[i];
    }
    return prevH;
}
int hashTable_ctor(struct hashTable* ht, int (*hf)(char[]))
{
    for(int i = 0; i < 997; i++)
    {
        printf("\n1\n");
        ht->table[i] = new list_t;
        list_ctor(ht->table[i]);
    }
    ht->hashFunc = hf;
    return 0;
}
int hashTable_addElement(struct hashTable* ht, char element[])
{
    int i = ht->hashFunc(element) % 997;
    if (!isIncluded(ht, element, i))
        list_insertA(ht->table[i], ht->table[i]->lastNode, element);
    return 0;
}
//for element in hashtable
int isIncluded(hashTable* ht, char element[], int hfuncResult)
{
    node* n = ht->table[hfuncResult]->firstNode;

    if(ht->table[hfuncResult]->length > 0)
        do
        {
            if(!strcmp(n->value, element))
                return 1;
            else n = n->next;
        }while(n != ht->table[hfuncResult]->lastNode && n != NULL);
    return 0;
}
